import java.util.Scanner;


/**
 * Created with IntelliJ IDEA.
 * Description:BOKD
 * User: 34321
 * Date: 2024-11-07
 * Time: 10:28
 */
public class Test {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            int idx = 0;//
            int[] names = new int[n*k];//记录第idx组数据的字段
            int[] values = new int[n*k];//记录第idx组数据的值
            for (int i = 0; i < n; i++) {
                int op = scanner.nextInt();
                if (op == 1) {
                    // p次插入操作
                    int p = scanner.nextInt();
                    for (int j = 0; j < p; j++) {
                        names[++idx] = scanner.nextInt();
                        values[idx] = scanner.nextInt();
                    }
                } else {
                    // 查询操作
                    int x = scanner.nextInt();
                    int min = scanner.nextInt();
                    int max = scanner.nextInt();
                    int count = 0;
                    //枚举查找
                    for (int j = 1; j <= idx; j++) {
                        if (names[j] == x && values[j] >= min && values[j] <= max) {
                            count++;
                        }
                    }
                    System.out.println(count);
                }
            }
            scanner.close();
        }

    }



//    static class Person {
//        public String name;
//        public int age;
//
//        public Person(String name, int age) {
//            this.name = name;
//            this.age = age;
//            System.out.println("构造方法执行");
//        }
//
//        {
//            System.out.println("实例代码块执行");
//        }
//
//        static {
//            System.out.println("静态代码块执行");
//        }
//    }
//
//    public static class TestDemo {
//        public static void main(String[] args) {
//            Person person1 = new Person("xiaoxin",10);
//            System.out.println("============================");
//            Person person2 = new Person("hyzs",20);
//        }
//    }






